home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / RCS / Mem_Size.c,v < prev    next >
Encoding:
Text File  |  1991-12-03  |  3.3 KB  |  161 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.3.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     88.07.25.11.10.55;  author ouster;  state Exp;
  11. branches 1.3.1.1;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     88.06.18.17.17.33;  author ouster;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     88.05.20.15.49.27;  author ouster;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24. 1.3.1.1
  25. date     91.12.02.20.38.38;  author kupfer;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29.  
  30. desc
  31. @@
  32.  
  33.  
  34. 1.3
  35. log
  36. @Lint.
  37. @
  38. text
  39. @/* 
  40.  * Mem_Size.c --
  41.  *
  42.  *    Source code for the "Mem_Size" library procedure.  See memInt.h
  43.  *    for overall information about how the allocator works.
  44.  *
  45.  * Copyright 1985, 1988 Regents of the University of California
  46.  * Permission to use, copy, modify, and distribute this
  47.  * software and its documentation for any purpose and without
  48.  * fee is hereby granted, provided that the above copyright
  49.  * notice appear in all copies.  The University of California
  50.  * makes no representations about the suitability of this
  51.  * software for any purpose.  It is provided "as is" without
  52.  * express or implied warranty.
  53.  */
  54.  
  55. #ifndef lint
  56. static char rcsid[] = "$Header: Mem_Size.c,v 1.2 88/06/18 17:17:33 ouster Exp $ SPRITE (Berkeley)";
  57. #endif not lint
  58.  
  59. #include <stdio.h>
  60. #include "memInt.h"
  61.  
  62.  
  63. /*
  64.  * ----------------------------------------------------------------------------
  65.  *
  66.  * Mem_Size --
  67.  *
  68.  *      Return the size of a previously-allocated storage block.
  69.  *
  70.  * Results:
  71.  *      The return value is the size of *blockPtr, in bytes.  This is
  72.  *    the total usable size of the block.  It may be slightly greater
  73.  *    than the size actually requested from malloc, since the size
  74.  *    might have been rounded up to a convenient boundary.
  75.  *
  76.  * Side effects:
  77.  *    None.
  78.  *
  79.  * ----------------------------------------------------------------------------
  80.  */
  81.  
  82. ENTRY int
  83. Mem_Size(blockPtr)
  84.     Address blockPtr;    /* Pointer to storage block.  Must have been the
  85.              * return value from malloc at some previous time. */
  86. {
  87.     int admin;
  88.  
  89.     LOCK_MONITOR;
  90.  
  91.     if (!memInitialized) {
  92.         panic("Mem_Size: allocator not initialized!\n");
  93.     UNLOCK_MONITOR;
  94.     return(0);            /* should never get here */
  95.     }
  96.  
  97.     /* 
  98.      *  Make sure that this block bears some resemblance to a
  99.      *  well-formed storage block.
  100.      */
  101.     
  102.     blockPtr -= sizeof(AdminInfo);
  103.     admin = GET_ADMIN(blockPtr);
  104.     if (!IS_IN_USE(admin)) {
  105.     if (IS_DUMMY(admin)) {
  106.         panic("Mem_Size: storage block is corrupted\n");
  107.     } else {
  108.         panic("Mem_Size: storage block is free\n");
  109.     }
  110.     UNLOCK_MONITOR;
  111.     return(0);            /* (should never get here) */
  112.     }
  113.  
  114.     UNLOCK_MONITOR;
  115.     return(SIZE(admin) - sizeof(AdminInfo));
  116. }
  117. @
  118.  
  119.  
  120. 1.3.1.1
  121. log
  122. @Initial branch for Sprite server.
  123. @
  124. text
  125. @d18 1
  126. a18 1
  127. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/Mem_Size.c,v 1.3 88/07/25 11:10:55 ouster Exp $ SPRITE (Berkeley)";
  128. @
  129.  
  130.  
  131. 1.2
  132. log
  133. @Use panic instead of Sys_Panic.
  134. @
  135. text
  136. @d18 1
  137. a18 1
  138. static char rcsid[] = "$Header: Mem_Size.c,v 1.1 88/05/20 15:49:27 ouster Exp $ SPRITE (Berkeley)";
  139. d21 1
  140. @
  141.  
  142.  
  143. 1.1
  144. log
  145. @Initial revision
  146. @
  147. text
  148. @d18 1
  149. a18 1
  150. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  151. d53 1
  152. a53 1
  153.         MemPanic("Mem_Size: allocator not initialized!\n");
  154. d67 1
  155. a67 1
  156.         MemPanic("Mem_Size: storage block is corrupted\n");
  157. d69 1
  158. a69 1
  159.         MemPanic("Mem_Size: storage block is free\n");
  160. @
  161.